package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Examination;
import cn.wolfcode.crm.mapper.ExaminationMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IExaminationService;
import cn.wolfcode.crm.util.ExaminationQueryObject;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ExaminationServiceImpl implements IExaminationService {

    @Autowired
    private ExaminationMapper examinationMapper;

    //保存和更新员工操作
    public int saveOrUpdate(Examination record) {
        if (record.getId() == null) {
            return examinationMapper.insert(record);
        } else {
            return examinationMapper.updateByPrimaryKey(record);
        }
    }

    //查询单个员工操作
    public Examination selectByPrimaryKey(Long id) {
        return examinationMapper.selectByPrimaryKey(id);
    }


    //员工列表操作
    public List<Examination> selectAll() {
        return examinationMapper.selectAll();
    }

    public PageResult query(ExaminationQueryObject qo) {
        int count = examinationMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Examination> data = examinationMapper.queryList(qo);
        return new PageResult(count, data);
    }

    public void delete(Long id) {
        examinationMapper.deleteByPrimaryKey(id);
    }

    public void audit(Long id) {
        examinationMapper.audit(id);
    }

}
